---
title: SentenceTransformers Embedder
sidebarTitle: SentenceTransformers
---

The `SentenceTransformerEmbedder` class is used to embed text data into vectors using the [SentenceTransformers](https://www.sbert.net/) library.

## Usage

```python sentence_transformer_embedder.py
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector
from agno.knowledge.embedder.sentence_transformer import SentenceTransformerEmbedder

# Embed sentence in database
embeddings = SentenceTransformerEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")

# Print the embeddings and their dimensions
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# Use an embedder in a knowledge base
knowledge = Knowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="sentence_transformer_embeddings",
        embedder=SentenceTransformerEmbedder(),
    ),
    max_results=2,
)
```

## Params

| Parameter                     | Type                        | Default                                    | Description                                                  |
| ----------------------------- | --------------------------- | ------------------------------------------ | ------------------------------------------------------------ |
| `id`                          | `str`                       | `sentence-transformers/all-MiniLM-L6-v2`   | The name of the SentenceTransformers model to use            |
| `dimensions`                  | `int`                       | `384`                                      | The dimensionality of the generated embeddings               |
| `sentence_transformer_client` | `Optional[SentenceTransformer]` | `None`                                 | Optional pre-configured SentenceTransformers client instance |
| `prompt`                      | `Optional[str]`             | `None`                                     | Optional prompt to prepend to input text                     |
| `normalize_embeddings`        | `bool`                      | `False`                                    | Whether to normalize returned vectors to have length 1       |

## Developer Resources
- View [Cookbook](https://github.com/agno-agi/agno/tree/main/cookbook/knowledge/embedders/sentence_transformer_embedder.py)
